package com.example.smartmallserver.demos.web.controller;

import com.example.smartmallserver.demos.web.pojo.Comment;
import com.example.smartmallserver.demos.web.pojo.Goods;
import com.example.smartmallserver.demos.web.service.IndexService;
import com.example.smartmallserver.demos.web.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//@CrossOrigin
@RestController
public class GoodsController {
    @Autowired
    IndexService indexService;
    @Autowired
    HttpSession session;
    @GetMapping("/goods/detail")
    Result getGoodsDetailById(Integer goodsId){
        Goods goods = indexService.getGoodsById(goodsId);
        return Result.success(goods);
    }

    @GetMapping("/cartTotalCount")
    Result getcartTotalCount(){
        Integer total = indexService.getCartCountById(session.getAttribute("id"));
        return Result.success(total);
    }

    @GetMapping("/comment/listRows")
    Result getGoodsComment(Integer goodsId){
        List<Comment> comments = indexService.getCommentByGoodsById(goodsId);
        return Result.success(comments);
    }
}
